import http from "@/util/http"
import {URL} from "@/api/url"

/**
 * 处理http响应
 *
 * @param response
 * @returns {*}
 */
function responseHandle(response) {
  let data = {};
  if (response && response.success) {
    //请求成功返回，响应的json数据
    data = response.data;
  } else {
    //请求失败，返回http错误信息
    data = response;
  }
  return data;
}

/**
 * 登录
 * @param parms
 */
export const login = async parms => {
  let response = await http.send(URL.login, parms, 'POST');
  return responseHandle(response);
};

/**
 * 登出
 */
export const logout = async () => {
  let response = await http.send(URL.logout);
  return responseHandle(response);
};

/**
 * 获取用户信息
 */
export const getUserInfo = async () => {
  let response = await http.send(URL.getUserInfo);
  return responseHandle(response);
};
